package class10;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.cn/problems/contains-duplicate/
 * 存在重复元素
 */
public class Code07_containsDuplicate {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4};
        boolean ans = containsDuplicate(arr);
        System.out.println("ans = " + ans);
    }

    public static boolean containsDuplicate(int[] arr) {
        Set<Integer> set = new HashSet<>();
        for (int e : arr) {
            if (!set.add(e)) {
                return true;
            }
        }
        return false;
    }
}
